<template>
  <div class="hello">
    <router-link to="/empForm">新增</router-link>
    <table border="1" align="center">
      <tr>
        <td>编号</td>
        <td>姓名</td>
        <td>住址</td>
        <td>介绍</td>
        <td>操作</td>
      </tr>
      <tr v-for="(emp,index) in emps" :key="index">
        <td>{{ emp.id }}</td>
        <td>{{emp.name}}</td>
        <td>{{emp.address}}</td>
        <td>{{ emp.content }}</td>
        <td>
          <button @click="deleteEmp(emp.id)">删除</button>
          <button @click="updateForm(emp.id)">修改</button>
        </td>
      </tr>
    </table>
  </div>
</template>
<script>
export default {
  name: 'Mytable',
  data () {
    return {
      emps: []
    }
  },
  created:function(){
    //调用java代码获取员工信息
    this.selectAll();
  },
  methods:{
    selectAll:function(){
      this.axios.get("/emps/selectAll").then(
        resp=>{
          this.emps = resp.data;
        }
      );
    },
    deleteEmp:function(id){
      if(confirm("是否确认删除？")){
        this.axios.delete("/emps/"+id).then(
          resp=>{
            if(resp.status==200){
              alert("删除成功！");
              this.selectAll();
            }
          }
        );
      }
    },
    updateForm:function(id){
      this.$router.push({path:"/updateForm",query:{id:id}});
    }
  }
}
</script>